<?php
ob_start();
define( '__ESPACE__', 'admin');
require_once('../starter.php');

$PWE_admin = new controler_admin();
$PWE_admin->deconnect();

if(isset($_GET) && isset($_GET['connexion']) && $_GET['connexion']==1){
    if(isset($_POST) && isset($_POST['login']) && $_POST['login'] !== '' && isset($_POST['password']) && $_POST['password'] !== ''){
        $user = modele_user::loginAdmin($_POST['login'],$_POST['password']);
        if($user !== null && $user->getLevel()<3){
            header('location: index.php');
            ob_end_flush();
        }
    }
}
?>
<!DOCTYPE html>
<html style="background-color:#CCCCCC;">
    <head>
        <title>Admin login</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="<?php echo $PWE_admin->getUiThemePath(); ?>" type="text/css" rel="stylesheet" media="all"/>
        <link href="css/style.css" type="text/css" rel="stylesheet" media="all"/>
        <script src="<?php echo $PWE_admin->getBaseURL(); ?>js/libs/jquery/jquery.js" type="text/javascript"></script>
        <script src="<?php echo $PWE_admin->getBaseURL(); ?>js/libs/jqueryui/jquery-ui.js" type="text/javascript"></script>
        <script src="<?php echo $PWE_admin->getBaseURL(); ?>js/libs/jqueryui/jquery-ui-datepicker-fr.js" type="text/javascript"></script>
        <script src="<?php echo $PWE_admin->getBaseURL(); ?>js/libs/jqueryui/jquery-ui-timepicker-fr.js" type="text/javascript"></script>
        <script src="<?php echo $PWE_admin->getBaseURL(); ?>admin/js/script.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $('#login').dialog();
                $('#submitBtn').button();
            });
        </script>
    </head>
    <body>
        <div id="login" title="Connexion à l'espace d'administration">
            <form action="?connexion=1" method="post" enctype="multipart/form-data">
                <label>e-mail</label><input type="texte" name="login"/><br/>
                <label>mot de passe</label><input type="password" name="password"/><br/>
                <input id="submitBtn" type="submit" name="submit" value="connexion" />
            </form>
        </div>
    </body>
</html>
<?php ob_end_flush(); ?>